#include <iostream>
#include <vector>

using namespace std;

int trap(vector<int>& height) {
    int ans = 0;
    int left = 0, right = height.size() - 1;
    int left_max = 0, right_max = 0;

    while (left < right)
    {
        if (height[left] < height[right])
        {
            if (height[left] < left_max)
                ans += left_max - height[left];
            else
                left_max = height[left];
            ++left;
        }
        else
        {
            if (height[right] < right_max)
                ans += right_max - height[right];
            else
                right_max = height[right];
            --right;
        }
    }

    return ans;
}

int main()
{

	return 0;
}